//
//  PeopleDetailTopView.m
//  TQY
//
//  Created by 甘世清 on 2024/10/17.
//

#import "PeopleDetailTopView.h"

@implementation PeopleDetailTopView

- (void)SQ_UIViewForSelfView{
    [self addSubview:self.chatView];
    [self.chatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.mas_equalTo(70);
    }];
    [self addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self);
        make.bottom.equalTo(self.chatView.mas_top);
    }];
    UIImageView * bgImage = [[UIImageView alloc]init];
    bgImage.image = SQGetImage(@"阴影");
    bgImage.contentMode = UIViewContentModeScaleAspectFill;
    bgImage.clipsToBounds = YES;
    [self.headerView addSubview:bgImage];
    [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(self.headerView);
            make.height.mas_equalTo(90);
    }];
    
    [self.headerView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView).offset(16);
        make.bottom.equalTo(self.headerView.mas_bottom).offset(-30);
    }];
    [self.headerView addSubview:self.genderImage];
    [self.genderImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(16);
            make.left.equalTo(self.nameLabel.mas_right).offset(8);
            make.centerY.equalTo(self.nameLabel);
    }];
    [self.headerView addSubview:self.realStatusImage];
    [self.realStatusImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(16);
        make.left.equalTo(self.genderImage.mas_right).offset(8);
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.headerView addSubview:self.vipImage];
    [self.vipImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.left.equalTo(self.realStatusImage.mas_right).offset(8);
        make.centerY.equalTo(self.nameLabel);
    }];
  
    [self.headerView addSubview:self.cityLabel];
    [self.cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.nameLabel);
            make.top.equalTo(self.nameLabel.mas_bottom).offset(10);
    }];
    [self.headerView addSubview:self.ageLabel];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.cityLabel.mas_right).offset(8);
        make.centerY.equalTo(self.cityLabel);
    }];
    [self addSubview:self.rightBtn];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgImage.mas_right).offset(-10);
        make.bottom.equalTo(bgImage.mas_bottom).offset(-10);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(60);
    }];
    WS(weakSelf);
    [self.chatView.vipBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_ButtonClick];
    }];
}
- (void)setModel:(PeopleModel *)model{
    _model = model;
    [self.headerView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"1")];
    self.nameLabel.text = model.name;
    if ([model.gender isEqualToString:@"2"]) {
        self.genderImage.image = SQGetImage(@"女");
    } else {
        self.genderImage.image = SQGetImage(@"男");
    }
    if (model.isVip) {
        self.vipImage.hidden = NO;
    } else {
        self.vipImage.hidden = YES;
    }
    if (model.realStatus == 2) {
        self.realStatusImage.image = SQGetImage(@"renzheng");
    } else {
        self.realStatusImage.image = SQGetImage(@"unrenzheng");
    }
    
    if ([model.age isNotEmpty]) {
        self.ageLabel.text = [NSString stringWithFormat:@"%@%@",model.age,SQNSLocalString(@"岁")];
    }  
    if (self.model.distance > 0) {
        if (model.distance <1000) {
            self.cityLabel.text = [NSString stringWithFormat:@"%@ 距您:%.fm",model.city,model.distance ];
        } else  {
            self.cityLabel.text = [NSString stringWithFormat:@"%@ 距您:%.fkm",model.city,model.distance/1000.f];
        }
    }else{
        self.cityLabel.text = self.model.city;
    }
  
    if ([model.wx isNotEmpty]) {
        self.chatView.hidden = NO;
        [self.chatView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(70);
        }];
        if ( [UserModel share].isVip ) {
            self.chatView.vipBtn.text = SQNSLocalString(@"点击复制");
            self.chatView.chatLabel.text = model.wx;
        } else {
            self.chatView.vipBtn.hidden = NO;
            self.chatView.vipBtn.text = SQNSLocalString(@"立即解锁");
            self.chatView.chatLabel.text = @"******";
        }
    } else {
        self.chatView.hidden = YES;
        [self.chatView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    }
    
    if ([[UserModel share].userid isEqualToString:self.model.userid]) {
        self.rightBtn.hidden = YES;
        self.chatView.hidden = YES;
        [self.chatView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    } else {
        self.rightBtn.hidden = NO;
    }
    
}
-(void)SQ_ButtonClick{
    if ([UserModel share].isVip) {
        UIPasteboard *pab = [UIPasteboard generalPasteboard];
        pab.string = self.model.wx;
          if (pab == nil) {
              [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"复制失败")];
          } else {
              [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"复制成功")];
          }
    } else {
        [VipPopView SQ_Show];
    }
}

-(void)SQ_headerViewButtonClick{
    YBIBImageData * data = [YBIBImageData new];
    data.imageURL = SQURLImage(self.model.portrait);
    data.projectiveView = self.headerView.headerImage;
    YBImageBrowser * brow = [YBImageBrowser new];
    brow.dataSourceArray = @[data];
    brow.currentPage =  0;
    [brow show];
}
- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        [_headerView.btn addTarget:self action:@selector(SQ_headerViewButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _headerView;
}

- (UIImageView *)genderImage{
    if (!_genderImage) {
        _genderImage = [[UIImageView alloc]init];
        _genderImage.image = SQGetImage(@"女");
    }
    return _genderImage;
}
- (UILabel *)ageLabel{
    if (!_ageLabel) {
        _ageLabel = [[UILabel alloc]init];
        _ageLabel.font = FONT_REGULAR(12);
        _ageLabel.textColor = UIColor.blackColor;
    }
    return _ageLabel;
}
- (UILabel *)cityLabel{
    if (!_cityLabel) {
        _cityLabel = [[UILabel alloc]init];
        _cityLabel.font = FONT_REGULAR(12);
        _cityLabel.textColor = UIColor.blackColor;
    }
    return _cityLabel;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(24);
        _nameLabel.textColor = UIColor.blackColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}
- (SQCustomButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(44, 44) midmargin:0];
        _rightBtn.image = SQGetImage(@"聊天");
    }
    return _rightBtn;
}
 

- (UIImageView *)vipImage{
    if (!_vipImage) {
        _vipImage = [[UIImageView alloc]init];
        _vipImage.image = SQGetImage(@"huiyuanquanyi");
    }
    return _vipImage;
}

- (UIImageView *)realStatusImage{
    if (!_realStatusImage) {
        _realStatusImage = [[UIImageView alloc]init];
        _realStatusImage.image = SQGetImage(@"unrenzheng");
    }
    return _realStatusImage;
}
- (PeopleChatBottomView *)chatView{
    if (!_chatView) {
        _chatView = [[PeopleChatBottomView alloc]initWithFrame:CGRectZero];;
    }
    return _chatView;
}
@end
